package net.caixiaomi.info.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sobot.chat.utils.ScreenUtils;

import net.caixiaomi.info.R;
import net.caixiaomi.info.app.CommonApp;
import net.caixiaomi.info.base.quickadapter.BaseMultiItemQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.base.quickadapter.entity.MultiItemEntity;
import net.caixiaomi.info.helper.AppHelper;
import net.caixiaomi.info.interfaces.SimpleEqualRatioTarget;
import net.caixiaomi.info.model.ActiveEntity;
import net.caixiaomi.info.model.MatchingItem;
import net.caixiaomi.info.util.Constants;
import net.caixiaomi.info.util.SchemeUtil;
import net.caixiaomi.smartrefresh.layout.SmartRefreshLayout;

import java.util.List;

/**
 * Created by mac on 2018/9/5.
 */

public class ActiveItemAdapter extends BaseQuickAdapter<MultiItemEntity, BaseViewHolder> {

    private int mType;

    public ActiveItemAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        bindView(helper, item);
    }

    private void bindView(BaseViewHolder helper, MultiItemEntity item){
        String title="";
        String url="";
        ImageView imgView=helper.getView(R.id.active_img);

        if(item.getItemType()==Constants.ITEM_MATCH_LIVE0){
            ActiveEntity active= (ActiveEntity) item;
            title=active.getBannerName();
            url=active.getBannerImage();
        }else{

        }
        helper.setText(R.id.active_tv,title);
        int width = CommonApp.mScreenWidth- ScreenUtils.dip2px(mContext,30);
        int height=210*width/535;
        LinearLayout.LayoutParams params= (LinearLayout.LayoutParams) imgView.getLayoutParams();
        params.width=width;
        params.height=height;
        imgView.setLayoutParams(params);
        Glide.with(imgView.getContext()).load(url).into(imgView);

        RelativeLayout rrl=helper.getView(R.id.active_off);
        if(mType==0){
            rrl.setVisibility(View.GONE);
            helper.setVisible(R.id.active_go,true);
        }else{
            rrl.setVisibility(View.VISIBLE);
            RelativeLayout.LayoutParams params1= (RelativeLayout.LayoutParams) rrl.getLayoutParams();
            params1.width=width;
            params1.height=height;
            rrl.setLayoutParams(params1);
            helper.setVisible(R.id.active_go,false);
        }

    }

    public void setType(int type){
        mType=type;
    }
}
